package com.lyf.design.learn.j2e.interceptorfilter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author LYF
 * @date 2022/6/27
 */
public class AuthFilter implements Filter{



    @Override
    public void preHandle(String req) throws Exception {
          if(check(req)){
              System.out.println("通过认证");
          }else{
              throw new Exception("未能通过认证");
//              System.out.println("未能通过认证");
//              return;
          }
    }

    @Override
    public void postHandle(String req) {
        System.out.println("认证收尾工作");
    }

    boolean check(String req){
        // 模拟数据库
        List<String> list = new ArrayList<>();
        list.add("success");
        list.add("ok");
        if(list.contains(req)){
            return true;
        }
        return false;
    }

}
